package com.wtgroup.demo.mianshi.容器.链表;

import com.wtgroup.demo.common.bean.LinkNode;

/**
 * 链表反转
 *
 * @author dafei
 * @version 0.1
 * @date 2021/4/16 15:12
 */
public class D1_单链表反转 {


    public static void main(String[] args) {
        LinkNode linkNode = LinkNode.toListNode(1, 2, 3, 4, 5, 6, 7, 8);
        LinkNode.print(run(linkNode));
    }

    public static LinkNode run(LinkNode head) {
        LinkNode pre = null;
        LinkNode next = null;
        while (head != null) {
            next = head.next;
            head.next = pre;
            pre = head;
            head = next;
        }

        return pre;
    }

}
